<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    function runQueue (promises) {
      promises.reduce((previousPromise, nextPromise) => {
        return previousPromise.then(() => {
          return nextPromise.then(id => {
            console.log(id)
          })
        })
      }, Promise.resolve())
    }

    function createPromise (time, id) {
      return new Promise(resolve => {
        setTimeout(() => {
          // console.log(id)
          resolve(id)
        }, time);
      })
    }

    runQueue([
      createPromise(1000, 1),
      createPromise(50, 2),
      createPromise(5, 3)
    ])


    // new Promise((resolve, reject) => {
    //   // p1
    //   resolve()
    // })
    //   .then(result => {
    //     // p2
    //     return result
    //   })
    //   .then(result => {
    //     // p3
    //     return result
    //   })
  </script>
</body>
</html>